function PagesManager() {}

PagesManager.inherits(Object, {
	hideClass : "hide",
	currentPage : "content-manageProduct",
	lastPage : "content-manageProduct",
	history : [Pages.manageProduct],
	currentController : null,
	
	setPage : function(page, isPopup, data) {
		if(isPopup) {
			$id("body").addClass("hideScroll");
		} else {
			$id(this.currentPage).addClass(this.hideClass);
		}
		this.showPage(page, isPopup, data);		
	},
	
	hidePage : function() {
		$id(this.currentPage).addClass(this.hideClass);
		$id("popup").addClass(this.hideClass);
		$id("body").removeClass("hideScroll");
		this.currentPage = this.lastPage;
	},
	
	showPage : function(page, isPopup, data) {	
		this.lastPage = this.currentPage;	
		this.currentPage = page.id;
		if(isPopup) {
			$id("popup").removeClass(this.hideClass);
		} else {
			this.addHistory(page);
		}
		$id(this.currentPage).removeClass(this.hideClass);
		var ctrl = page.controllers[0];
		if(ctrl) {
			this.currentController = new ctrl(page, data);
		}
	},
	
	addHistory : function(page) {
		var length = this.history.length;
		if(length == 0 || this.history[length - 1].id != page.id) {
			this.history.push(page);
		}
	},
	
	backPage : function(state) {
		if(!$id("popup").hasClass(this.hideClass)) {
			this.hidePage();
		} else if(state < 0){
			if(this.history.length > 1) this.history.pop();
			this.setPage(this.history[this.history.length-1], false);
		}
	}	
	
});

var pagesManager = new PagesManager();